// pages/mine/collection/collection.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    resume: [],
    call: [],
    stay: [],
    page_resume: 1,
    page_call: 1,
    page_stay: 1,

    //切换
    currentData: 0,
  },
  
  //简历加载
  load_resume: function(e) {
    let that = this;
    let page_resume = this.data.page_resume;
    page_resume = page_resume + 1;
    that.setData({
      page_resume: page_resume
    })
    this.list_resume();
    console.log("update")
  },
  //简历加载
  resumeList(_page){
    let that=this;
    wx.request({
      url: app.globalData.url + 'api/recruit/link/up/list',
      method: 'POST',
      data: {
        token: app.globalData.token,
        type:1,
        page: _page,
      },
      success: function (e) {
        // console.log(e)

        if (e.data.data.list.current_page > e.data.data.list.last_page) {
          console.log("到底了");
          wx.showToast({
            title: '到底啦~',
            icon: 'none',
          })
        } else {
          if (that.data.page_resume ==1) {
            that.setData({
              resume: e.data.data.list.data,
            })
          } else {
            // console.log("不不不不不");
            let resume = that.data.resume;
            let _resume = e.data.data.list.data;
            resume.push(..._resume)
            console.log(resume);
            that.setData({
              resume: resume,
            })
          }
        }
        wx.hideLoading();
      }
    })
  },
  // 简历加载
  list_resume: function(e) {
    let that = this;
    let page_resume = this.data.page_resume
    that.resumeList(page_resume);
    // wx.showLoading({
    //   icon: 'none',
    // })
  },

  //拨电话加载
  load_call: function (e) {
    let that = this;
    let page_call = this.data.page_call;
    page_call = page_call + 1;
    that.setData({
      page_call: page_call
    })
    this.list_call();
    console.log("update")
  },
  //拨电话加载
  callList(_page) {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/recruit/link/up/list',
      method: 'POST',
      data: {
        token: app.globalData.token,
        type: 3,
        page: _page,
      },
      success: function (e) {
        // console.log(e)

        if (e.data.data.list.current_page > e.data.data.list.last_page) {
          console.log("到底了");
          wx.showToast({
            title: '到底啦~',
            icon: 'none',
          })
        } else {
          if (that.data.page_call == 1) {
            that.setData({
              call: e.data.data.list.data,
            })
          } else {
            // console.log("不不不不不");
            let call = that.data.call;
            let _call = e.data.data.list.data;
            call.push(..._call)
            console.log(call);
            that.setData({
              call: call,
            })
          }
        }
        wx.hideLoading();
      }
    })
  },
  // 拨电话加载
  list_call: function (e) {
    let that = this;
    let page_call = this.data.page_call
    that.callList(page_call);
    // wx.showLoading({
    //   icon: 'none',
    // })
  },

  //留电话加载
  load_stay: function (e) {
    let that = this;
    let page_stay = this.data.page_stay;
    page_stay = page_stay + 1;
    that.setData({
      page_stay: page_stay
    })
    this.list_stay();
    console.log("update")
  },
  //留电话加载
  stayList(_page) {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/recruit/link/up/list',
      method: 'POST',
      data: {
        token: app.globalData.token,
        type: 2,
        page: _page,
      },
      success: function (e) {
        // console.log(e)

        if (e.data.data.list.current_page > e.data.data.list.last_page) {
          console.log("到底了");
          wx.showToast({
            title: '到底啦~',
            icon: 'none',
          })
        } else {
          if (that.data.page_stay == 1) {
            that.setData({
              stay: e.data.data.list.data,
            })
          } else {
            // console.log("不不不不不");
            let stay = that.data.stay;
            let _stay = e.data.data.list.data;
            stay.push(..._stay)
            console.log(stay);
            that.setData({
              stay: stay,
            })
          }
        }
        wx.hideLoading();
      }
    })
  },
  // 留电话加载
  list_stay: function (e) {
    let that = this;
    let page_stay = this.data.page_stay
    that.stayList(page_stay);
    // wx.showLoading({
    //   icon: 'none',
    // })
  },







  
  //切换 Start
  //获取当前滑块的index
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  //切换 End

  //详情
  go_detail: function(e) {
    console.log(e.currentTarget.dataset.deatil_id)
    let deatil_id = e.currentTarget.dataset.deatil_id;
    wx.navigateTo({
      url: '../../recruit/detail/detail?deatil_id=' + deatil_id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    this.list_resume();
    this.list_call();
    this.list_stay();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    this.setData({
      collects: [],
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})